package com.xingxue.logistics.common.vo;

import com.github.pagehelper.PageInfo;

import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.List;

/**
 * @author Kris at 2018/9/6 17:03
 */
public class Page<T> {
    /**
     * 总共数据量
     */
    private int total;
    /**
     * 当前这页的数据
     */
    private List<T> rows;

    public Page() {
    }

    public Page(int total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }

    /**
     * 根据Mybatis PageHelper的PageInfo对象实例一个Page对象
     * @param pageInfo
     */
    public Page (PageInfo pageInfo){
        this.total = (int)pageInfo.getTotal();
        this.rows = pageInfo.getList();
    };

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, new MultilineRecursiveToStringStyle())
                .append("total", total)
                .append("rows", rows)
                .toString();
    }
}
